# coding: utf-8
try:
    import time, requests, re, hashlib, datetime, sys, os, random
except Exception as e:
    t = re.findall("d '(.*?)'", str(e))[0]
    print(f'{t}依赖未安装')
    sys.exit()

appid ='wx7b6272c42fa733a7'#line:2
headers ={'User-Agent':'Mozilla/5.0 (Linux; Android 9; PBBT00 Build/PPR1.180610.011; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/70.0.3538.110 Mobile Safari/537.36 MMWEBID/3625 MicroMessenger/7.0.17.1720(0x27001134) Process/tools WeChat/arm32 NetType/4G Language/zh_CN ABI/arm64',}#line:3
host ='http://39.108.184.87'#line:4
def sign (OO00OOO0O0O0OO00O ):#line:5
    O0O00000OO000O000 =hashlib .md5 (OO00OOO0O0O0OO00O .encode ()).hexdigest ()#line:6
    OO00000O0O00O0OO0 ="scsc%^&*"+O0O00000OO000O000 +"19319#$%^&*((*&^%$#@#RFGHJ%^KAfghfg"#line:7
    OO0O00000O0OO0O0O =hashlib .md5 (OO00000O0O00O0OO0 .encode ()).hexdigest ()#line:8
    return OO0O00000O0OO0O0O #line:9
def timi_new ():#line:10
    return str (int (time .time ()*1000 ))#line:11
def post_qrcode ():#line:12
    try :#line:13
        O000O000O00OO0OO0 =requests .post (f'http://open.weixin.qq.com/connect/app/qrconnect?appid={appid}&bundleid=(null)&scope=snsapi_userinfo&state=w&from=message&isappinstalled=0',headers =headers ).text #line:16
        OOOOO0O0O00O0OOOO =re .findall ('auth_qrcode" src="(.*?)" />',O000O000O00OO0OO0 )[0 ]#line:17
        OOO000000OO00OOO0 =OOOOO0O0O00O0OOOO .split ('qrcode/')[1 ]#line:18
        return OOO000000OO00OOO0 #line:19
    except Exception as OOO000OOOO00OOOO0 :#line:20
        print (OOO000OOOO00OOOO0 )#line:21
def gettasklist (OOOO0OO0000O0O0OO ,O00OOOO00OO0O000O ,O000OOO0OO0OOOO0O ):#line:22
    try :#line:23
        O00OOO0OO0O0OO00O =requests .request ('get',f'{host}/api/gettasklist.asp?username={OOOO0OO0000O0O0OO}&password={O00OOOO00OO0O000O}&page=1&y=1&appid={appid}&k={O000OOO0OO0OOOO0O}').json ()#line:25
        if O00OOO0OO0O0OO00O ['ret']=='0':#line:27
            print (f"【账号信息】:任务状态:{O00OOO0OO0O0OO00O['date'][0]['State']}")#line:28
            if O00OOO0OO0O0OO00O ['date'][0 ]['State']=='二维码已失效'or O00OOO0OO0O0OO00O ['date'][0 ]['State']=='管理员终止':#line:29
                return True #line:30
        return False #line:31
    except Exception as O0O0000000OO0OOOO :#line:32
        print (O0O0000000OO0OOOO )#line:33
def post_code (OOO00OO00OO00000O ,OOOO0OO000O0000O0 ,O0OOOOOOOOOOOO00O ,O000OOOOOOOOOOOO0 ):#line:34
    OOOO000OO00O000OO =int (time .time ())#line:35
    try :#line:36
        while True :#line:37
            if gettasklist (OOOO0OO000O0000O0 ,O0OOOOOOOOOOOO00O ,O000OOOOOOOOOOOO0 ):#line:38
                return False #line:39
            OO00OO00O00O00OO0 =requests .post (f'http://long.open.weixin.qq.com/connect/l/qrconnect?uuid={OOO00OO00OO00000O}&_={OOOO000OO00O000OO})',headers =headers ).text #line:40
            if '405'in OO00OO00O00O00OO0 :#line:41
                OO00OO000OOO0O0O0 =re .findall ("wx_code='(.*?)';",OO00OO00O00O00OO0 )[0 ]#line:42
                return OO00OO000OOO0O0O0 #line:43
            time .sleep (3 )#line:44
    except Exception as O000000OO0O00000O :#line:45
        print (O000000OO0O00000O )#line:46
def post_dl (OO000O00OO00O0OO0 ):#line:47
    try :#line:48
        OOOO0O0OO0OOOO0O0 =f'__{timi_new()}'#line:49
        O0O00O0O00000000O ={'timestamp':str (timi_new ()),'sign':sign (OOOO0O0OO0OOOO0O0 ),'signstring':OOOO0O0OO0OOOO0O0 ,'version':'3.1.4195311','janalytics':'c167f56858dc424ee3d617c9','Host':'scsc.sc19319.com','User-Agent':'okhttp/4.9.1',}#line:58
        OOO0O0O00000O00O0 =requests .request ('get','http://scsc.sc19319.com/loginToken',headers =O0O00O0O00000000O ).json ()#line:59
        if 'status'in OOO0O0O00000O00O0 :#line:60
            if OOO0O0O00000O00O0 ['status']==200 :#line:61
                O0O0OO0O0OOOO0OOO ={"loginToken":OOO0O0O00000O00O0 ['data'],"code":OO000O00OO00O0OO0 ,"loginType":"生成世朝"}#line:66
                O0O0OOOO00O0OOO0O =f'_code={OO000O00OO00O0OO0}&loginToken={OOO0O0O00000O00O0["data"]}&loginType=_{timi_new()}'#line:67
                O0OO0OO00O0O00000 ={'timestamp':str (timi_new ()),'sign':sign (O0O0OOOO00O0OOO0O ),'signstring':O0O0OOOO00O0OOO0O ,'version':'3.1.4195311','janalytics':'c167f56858dc424ee3d617c9','Host':'scsc.sc19319.com','User-Agent':'okhttp/4.9.1',}#line:76
                O00OO0OO000OO0OOO =requests .request ('post','http://scsc.sc19319.com/login',headers =O0OO0OO00O0O00000 ,data =O0O0OO0O0OOOO0OOO ).json ()#line:77
                if 'status'in O00OO0OO000OO0OOO :#line:78
                    if O00OO0OO000OO0OOO ['status']==200 :#line:79
                        print ('【账号信息】:登录成功')#line:80
                        return O00OO0OO000OO0OOO ['data']['token']#line:81
                    if O00OO0OO000OO0OOO ['status']==500 :#line:82
                        print (O00OO0OO000OO0OOO ['message'])#line:83
    except Exception as OO00O0OOOOOOO000O :#line:85
        print (OO00O0OOOOOOO000O )#line:86


def addtask(elephant_user, elephant_pswd, elephant_Task_ID):
    uuid = post_qrcode()
    body = f'zcgqewm=https://open.weixin.qq.com/connect/confirm?uuid={uuid}'
    hea = {'Charset': 'UTF-8', 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
           'Cache-Control': 'no-cache', 'accept': 'application/json,text/html', 'Content-Length': '86',
           'User-Agent': 'Dalvik/2.1.0(Linux;U;Android12;2201122CBuild/SKQ1.211006.001)',
           'Host': '39.108.184.87', 'Connection': 'Keep-Alive', 'Accept-Encoding': 'gzip', }
    try:
        resp = requests.post(f'{host}/api/addtask.asp?username={elephant_user}&password={elephant_pswd}&zcsqrwid={elephant_Task_ID}',headers=hea, data=body).json()
        if 'msg' in resp:
            print(f'【账号信息】:提交任务:{resp["msg"]}')
        else:
            print(resp)
        code = post_code(uuid, elephant_user, elephant_pswd, elephant_Task_ID)
        if code:
            return post_dl(code)
    except Exception as e:
        print(e)
        print('大象任务编号过期或者被大象黑')
        return None
